home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacMETH 3.2.1 / MacMETH Manual 1992 / Manual Examples / StringExample.MOD < prev    next >
Encoding:
Text File  |  1992-10-09  |  1.3 KB  |  41 lines  |  [TEXT/MEDT]

  1. MODULE StringExample; (* shows the use of the string procedures *)
  2.  
  3.         FROM     String    IMPORT last, Length, Occurs, Copy;
  4.         FROM     InOut      IMPORT termCH, WriteString, WriteLn, ReadString;
  5.         
  6.           VAR       PathName    : ARRAY [0..63] OF CHAR;
  7.                 FileName     : ARRAY [0..31] OF CHAR;
  8.         
  9.         PROCEDURE SplitPath(VAR Path : ARRAY OF CHAR; VAR Name : ARRAY OF CHAR);
  10.             (* splits a complete file name ('Path') into the actual path and the file name *)
  11.             (* with the extension. The path is returned in 'Path', the file name in 'Name'.*)
  12.             VAR i,j : INTEGER;
  13.         BEGIN (* SplitPath *)
  14.             (* Find last ":" in the path *)
  15.             i := -1;
  16.             WHILE (i < Length(Path)) DO        (* Length(s) # HIGH(s) !! *)
  17.                 j := i;
  18.                 i := Occurs(Path,i+1,":");
  19.             END (* WHILE *);
  20.             INC(j);
  21.                 Copy(Name,Path,j,last);
  22.         Path[j] := 0C;            (* Quicker than 'Delete(Path,j,last)' *)
  23.         END SplitPath;
  24.  
  25.         BEGIN (* StringExample *)
  26.         LOOP
  27.                 WriteLn;
  28.                 WriteString("Enter a complete file name (including the path): ");
  29.             ReadString(PathName);
  30.             IF termCH < " " THEN
  31.                 WriteString(" -- escape"); EXIT;
  32.             END (* IF *);
  33.             SplitPath(PathName,FileName);
  34.             WriteLn;
  35.                 WriteString(" The path name is : "); WriteString(PathName); WriteLn;
  36.         WriteString(" The file name is : "); WriteString(FileName); WriteLn;
  37.             WriteLn;
  38.         END (* LOOP *);
  39.     END StringExample.
  40.  
  41.